
function MenuInit(){
    
    var menuItems = document.getElementById("menuitems");

    var h4s = menuItems.getElementsByTagName("H4");
    var h4len = h4s.length;

	for (var i=0; i < h4len; i++)
	{
		var h4 = h4s.item(i);
        h4.attachEvent("onmouseover", ItemHeadMouseover);
        h4.attachEvent("onmouseout", ItemHeadMouseout);
        h4.attachEvent("onclick", ItemHeadClick);        
    }

    var uls = menuItems.getElementsByTagName("UL");
    var ullen = uls.length;
    for(var i=1; i< ullen; i++){
        uls[i].style.display="none";
    }

	var lis = menuItems.getElementsByTagName("LI");
	var lilen = lis.length;
	
	for (var i=0; i < lilen; i++)
	{
		var li = lis.item(i);

        var selected = li.getAttribute("selected");

        if(selected==null){            
            li.attachEvent("onmouseenter", ItemMouseover);
            li.attachEvent("onmouseleave", ItemMouseout);
            li.attachEvent("onmousedown", ItemMousedown);
            li.attachEvent("onmouseup", ItemMouseup);
        }else{
            li.className = "selLI";            
        }

        var a = li.getElementsByTagName("A");
        if (a.length > 0)
        {
            var a0 = a[0];
            li.setAttribute("title", a0.title);

            if (a0.getAttribute("aoff") || selected!=null)
            {
                a0.outerHTML = "<a class=\"selA\">" + a0.innerHTML + "</a>";
            }
            else
            {
                li.setAttribute("status", a0.href);
                li.attachEvent("onclick", ItemClick);
            }
        }
    }
}

function ItemHeadMouseover()
{
	var h4 = window.event.srcElement;
	h4.className = "selH4";
}
function ItemHeadMouseout()
{
	var h4 = window.event.srcElement;
	h4.className = "";
}


function ItemMouseover()
{
	var li = window.event.srcElement;
	var status = li.getAttribute("status");
	if(status) window.status = status;	
    li.className = "focusLI";            
}

function ItemMouseout()
{
	window.status="";    
	var li = window.event.srcElement;
	li.className = "";
}

function ItemMousedown()
{
	var li = window.event.srcElement;
	if (li.tagName!= "LI") li = li.parentElement;	
    li.className = "clickLI";            	
}

function ItemMouseup()
{
	var li = window.event.srcElement;
	if (li.tagName!= "LI") li = li.parentElement;
	li.className = "";
}

function ItemClick()
{
	var li = window.event.srcElement;
	var a = li.getElementsByTagName("A");
	if (a.length == 0) return;
	
	if (window.event.shiftKey)
	{
		var target = a[0].target;
		a[0].target = "_new";
		a[0].click();
		a[0].target = target;
	}
	else{
		a[0].click();
	}
}

function ItemHeadClick()
{
	var h4 = window.event.srcElement;
	var div = h4.parentElement;
	
	var parentdiv = div.parentElement;
	if(parentdiv){
	    var items = parentdiv.getElementsByTagName("DIV");	    
	    if( items.length >0 ){
            for(var i=0; i<items.length; i++){
                var item = items[i];
                var ul = item.getElementsByTagName("UL");    
                if (ul.length == 0) continue;	

                if(item.id!=div.id){
                    ul[0].style.display = "none";
                }else{
                    ul[0].style.display = "block";
                }
            }        
	    }
    }
}